package org.user.datasource;


import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.tm.api.GlobalTransactionContext;
@Aspect
@Component
public class TransactionAdviceConfig {


    @Before("execution(* org.user.service.*.*(..))")
    public void before(JoinPoint joinPoint) throws TransactionException {
    }
 
    @AfterThrowing(throwing = "e", pointcut = "execution(* org.user.service.*.*(..))")
    public void doRecoveryActions(Throwable e) throws TransactionException {
    	System.out.println("发生异常,要回滚喽");
        if (!StringUtils.isBlank(RootContext.getXID()))
            GlobalTransactionContext.reload(RootContext.getXID()).rollback();
    }
 
    @AfterReturning(value = "execution(* org.user.service.*.*(..))", returning = "result")
    public void afterReturning(JoinPoint point, Object result) throws TransactionException {
    }


}
